
// 线样式枚举
const lineTypeEnum = [
  { key: '__________', value: 'solid' },
  { key: '----------', value: 'dashed' },
  { key: '................', value: 'dotted' },
];

// 图例位置枚举
export const legendPositionEnum = [
  { key: '顶部居中', value: 'top#center' },
  { key: '顶部居左', value: 'top#left' },
  { key: '顶部居右', value: 'top#right' },
  { key: '底部居中', value: 'bottom#center' },
  { key: '底部居左', value: 'bottom#left' },
  { key: '底部居右', value: 'bottom#right' },
  { key: '左侧居中', value: 'left#middle' },
  { key: '左侧居上', value: 'left#top' },
  { key: '左侧居下', value: 'left#bottom' },
  { key: '右侧居中', value: 'right#middle' },
  { key: '右侧居上', value: 'right#top' },
  { key: '右侧居下', value: 'right#bottom' }
];

export const fontSize = {
  name: '字号',
  code: 'fontSize',
  value: 14,
  min: 12,
  type: 'InputNumber',
  unit: 'px(像素)'
};

export const fontFamilyConfig = [
  { key: '微软雅黑', value: 'Microsoft YaHei' },
  { key: '京东朗正', value: 'jdfont' },
  { key: '思源黑体', value: 'siyuan' },
  { key: '宋体', value: 'SimSun' },
  { key: '黑体', value: 'STHeiti' },
  { key: '隶书', value: 'LiSu' },
  { key: '幼圆', value: 'YouYuan' },
  { key: '楷体', value: 'KaiTi_GB2312' },
  { key: 'Serif', value: 'Serif' },
  { key: 'Helvetica Neue', value: 'Helvetica Neue' },
  { key: 'Sans-serif', value: 'Sans-serif' },
  { key: 'Monospace', value: 'Monospace' },
  { key: 'Cursive', value: 'Cursive' },
  { key: 'Fantasy', value: 'Fantasy' }
];

export const fontFamily = {
  name: '字体',
  code: 'fontFamily',
  value: 'siyuan',
  type: 'Select',
  enumValue: fontFamilyConfig
};

export const color = {
  isGlobalControlled: true,
  name: '字体颜色',
  code: 'color',
  value: '',
  defaultValue: '#fff',
  type: 'ColorSelector'
};

// 新增属性 主题颜色
export function colorTheme() {
  return {
    isGlobalControlled: true,
    name: '字体颜色',
    code: 'color',
    value: '',
    themePath: 'lightColorList[0]',
    type: 'ColorSelector'
  };
}

export const fontWeightConfig = [
  { key: '正常', value: 'normal' },
  { key: '细体', value: 'lighter' },
  { key: '粗体', value: 'bold' },
  { key: '更粗', value: 'bolder' }
];

export const fontWeight = {
  name: '字体粗细',
  code: 'fontWeight',
  value: 'normal',
  type: 'Select',
  enumValue: fontWeightConfig
};

// 跟随主题设置字体颜色
export const fontConfigByGlobal = {
  isGlobalControlled: true,
  name: '文本设置',
  code: 'font',
  type: 'FontGroup',
  value: {
    fontSize: 12,
    fontFamily: 'siyuan',
    color: '',
    fontWeight: 'normal'
  }
};

export const fontConfig = {
  name: '文本设置',
  code: 'font',
  type: 'FontGroup',
  value: {
    fontSize: 12,
    fontFamily: 'siyuan',
    color: '#FFF',
    fontWeight: 'normal'
  }
};

export function fontThemeBuilder(params) {
  const {
    name, code, size, themePath, fontWeight: tfontWeight
  } = params || {};

  return {
    isGlobalControlled: true,
    name: name || '文本设置',
    code: code || 'font',
    type: 'FontGroup',
    value: {
      fontSize: size || 12,
      fontFamily: 'siyuan',
      color: '',
      fontWeight: tfontWeight || 'normal'
    },
    themePath: themePath || {
      color: 'lightColorList[1]'
    }
  };
}

export const textAlign = {
  name: '对齐方式',
  code: 'textAlign',
  value: 'center',
  type: 'Radio',
  enumValue: [
    { key: '左', value: 'left' },
    { key: '中', value: 'center' },
    { key: '右', value: 'right' }
  ]
};

export const rotate = {
  name: '旋转角度',
  code: 'rotate',
  type: 'InputNumber',
  value: 0,
  min: 0,
  max: 360
};

export const interval = {
  name: '智能隐藏',
  code: 'interval',
  type: 'CheckBox',
  value: false
};

export const colors = {
  name: '配色方案',
  code: 'colors',
  value: '#1B64EE,#07B57C,#6E32D8,#DC621E,#B4F572,#E8C21E,#484AEA,#24D7BD,#E048AF',
  defaultValue: '#1B64EE,#07B57C,#6E32D8,#DC621E,#B4F572,#E8C21E,#484AEA,#24D7BD,#E048AF',
  type: 'ColorDefault',
  enumValue: [
    {
      key: '方案一',
      value: '#1B64EE,#07B57C,#6E32D8,#DC621E,#B4F572,#E8C21E,#484AEA,#24D7BD,#E048AF',
    },
    {
      key: '方案二',
      value: '#184FF4,#008F62,#6921D8,#E78324,#68AD36,#C99800,#304DCA,#0BBAAB,#C21F87',
    },
    {
      key: '方案三',
      value: '#D59A38,#FFCC07,#DDCC6A,#32B0D8,#B95BF6,#47C250,#F59E72,#D75924,#7EE96F'
    }
  ]
};

// 图例设置
export const legendConfig = {
  code: 'legendConfig',
  name: '图例设置',
  children: [
    {
      name: '显示图例',
      code: 'show',
      type: 'CheckBox',
      value: true
    },
    {
      name: '文本',
      code: 'text',
      children: [
        fontFamily,
        fontSize,
        color,
        fontWeight
      ]
    },
    {
      name: '布局',
      code: 'layout',
      children: [
        {
          name: '图例布局',
          code: 'position',
          value: 'top#center',
          type: 'Select',
          enumValue: legendPositionEnum
        },
        {
          name: '左右间距',
          code: 'leftRight',
          value: 10,
          min: 0,
          type: 'InputNumber',
          unit: 'px(像素)'
        },
        {
          name: '上下间距',
          code: 'topBottom',
          value: 10,
          min: 0,
          type: 'InputNumber',
          unit: 'px(像素)'
        }
      ]
    }
  ]
};

export const splitLineConfigY = [
  {
    name: '是否显示',
    code: 'show',
    type: 'CheckBox',
    value: true
  },
  {
    name: '粗细',
    code: 'width',
    value: 1,
    type: 'InputNumber',
    max: 99,
    min: 1
  },
  {
    name: '样式',
    code: 'type',
    value: 'dashed',
    type: 'Select',
    enumValue: lineTypeEnum
  },
  {
    name: '颜色',
    code: 'color',
    value: 'rgba(110, 106, 122, 0.6)',
    type: 'ColorSelector'
  }
];

export const splitLineConfigX = [
  {
    name: '是否显示',
    code: 'show',
    type: 'CheckBox',
    value: true
  },
  {
    name: '粗细',
    code: 'width',
    value: 1,
    type: 'InputNumber',
    max: 99,
    min: 1
  },
  {
    name: '样式',
    code: 'type',
    value: 'dashed',
    type: 'Select',
    enumValue: lineTypeEnum
  },
  {
    name: '颜色',
    code: 'color',
    value: 'rgba(110, 106, 122, 0.6)',
    type: 'ColorSelector'
  }
];

// 辅助线设置
export const splitLine = {
  name: '辅助线设置',
  code: 'splitLine',
  children: [
    {
      name: '横向辅助线',
      code: 'rowLine',
      children: [...splitLineConfigX]
    },
    {
      name: '纵向辅助线',
      code: 'columnLine',
      children: [...splitLineConfigY]
    }
  ]
};

/**
 * 获取交互变量默认值
 * @param props
 * @returns {{}|*}
 */
export const getValueDefault = function (props) {
  if (!props) return null;
  const { events: { click: { action } } } = props;

  return action && action.active && action.default && action.useDefault
    ? action.default : null;
};
